// 按照左区间排序，每次选择能覆盖当前左端点且能到达最右端的区间
// 然后更新左端点

#include <iostream>
#include <algorithm>
using namespace std;

const int N = 100010;
struct Range
{
    int l, r;
    bool operator<(const Range &w) const
    {
        return l < w.l;
    }
} range[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int start = 0, end = 0;
    cin >> start >> end;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int l, r;
        cin >> l >> r;
        range[i] = {l, r};
    }
    sort(range, range + n);
    int res = 0;
    bool success = false;
    for (int i = 0; i < n; ++i)
    {
        int j = i, maxR = -2e9;
        while (j < n && range[j].l <= start)
        {
            // 这里判断的是当前的最大节点，需要先判断然后再进入下一位
            maxR = max(maxR, range[j].r);
            ++j;
        }
        // 如果当前的最大右节点都小于st，那说明没有答案，直接break即可
        if (maxR < start)
            break;
        ++res;
        if (maxR >= end)
        {
            success = true;
            break;
        }
        start = maxR;
        i = j - 1;
    }
    if (success)
        cout << res << endl;
    else
        cout << -1 << endl;
    return 0;
}
